package com.javasm.controller.JINXIAOController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.commons.basic.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.entity.JINXIAOEntity.SysRoleMenu;
import com.javasm.service.JINXIAOService.SysRoleMenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("sysRoleMenu")
public class SysRoleMenuController extends BaseController {
    @Resource
    private SysRoleMenuService sysRoleMenuService;

  
     @GetMapping("{id}")
    public AxiosResult selectById(@PathVariable Integer id)
    {
        SysRoleMenu obj = this.sysRoleMenuService.queryById(id);
        return suc(obj);
    }
    
    @GetMapping("ids/{ids}")
    public AxiosResult selectListByIds(@PathVariable String ids)
    {
        String[] idsArray = ids.split(",");
        List<SysRoleMenu> list = this.sysRoleMenuService.queryByIds(Arrays.asList(idsArray));
        return suc(list);
    }

    @GetMapping("list")
    @SuppressWarnings("unchecked")//List没有使用泛型， .@SuppressWarnings("unchecked") 隐藏所有的不安全的警告信息
    public AxiosResult selectList(SysRoleMenu obj, Integer pageNum, Integer pageSize)
    {
        if(pageNum==null) pageNum=1;
        if(pageSize==null) pageSize=10;
        PageHelper.startPage(pageNum,pageSize);
        List<SysRoleMenu> list = this.sysRoleMenuService.queryList(obj);
        PageInfo i = new PageInfo(list);
        return suc(i);
    }

    @PostMapping
    public AxiosResult add(@RequestBody SysRoleMenu obj)
    {
        Boolean r = this.sysRoleMenuService.insert(obj);
        return isok(r);
    }

    @PutMapping
    public AxiosResult update(@RequestBody SysRoleMenu obj)
    {
        Boolean r = this.sysRoleMenuService.update(obj);
        return isok(r);
    }

    @DeleteMapping("{ids}")
    public AxiosResult delByIds(@PathVariable String ids)
    {
        String[] idsArray = ids.split(",");
        Boolean r = this.sysRoleMenuService.deleteByIds(Arrays.asList(idsArray));
        return isok(r);
    }

}